package dyyx;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.dubbo.rpc.RpcContext;

import dyyx.util.CommUtil;
import dyyx.util.EchoUtil;
import dyyx.util.HostInfoUtil;
import dyyx.util.WebUtil;

public class HelloServiceImpl implements HelloService{

	public String echo(){
		// return "hello,"+System.currentTimeMillis();
		return EchoUtil.getEchoString();
	}
	
	
	public Map<String,Object> getInfo(){
		Map<String,Object> map = new HashMap<String,Object>();
		
		map.put("now",CommUtil.getNowDateString());
		map.put("ip", HostInfoUtil.getHostIp());
		map.put("webRoot", WebUtil.getWebRootDir());
		
		return map;
	}
	
	public String hello(String name) {
		
		Map<String,Object> context = new HashMap<>();
        RpcContext rpcContext = RpcContext.getContext();

		context.put("attachment_name", rpcContext.getAttachments().get("name"));
		
		context.put("isConsumerSide", rpcContext.isConsumerSide());
		context.put("isProviderSide", rpcContext.isProviderSide());
		context.put("remoteAddressString", rpcContext.getRemoteAddressString());
		context.put("remotePort", rpcContext.getRemotePort());
		context.put("remoteHostName", rpcContext.getRemoteHostName());
		// context.put("application", RpcContext.getContext().getUrl().getParameter("application"));

		
		
		String info = "hello,"+name+","+LocalDateTime.now()+",context="+context;
		return info;
	}
	
	public  Pet getPet(Pet pet) {
		return pet;
	}




}
